package com.cccyy.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LatelyNow {
    public static void main(String[] args) throws ParseException {
//        String str = "2022-03-02";
//        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
//        Date birthDate = format.parse(str);
//        String s = birthDate.toString();
//        System.out.println("最后转换出来的时间：" + s);

        String tranM = "202209";

        int i = latelyMonth(tranM.substring(2));
        System.out.println("最后转换出来的时间：" + i);
    }

    private static int latelyMonth(String tranYm) {
        int ym = Integer.parseInt(getTransTime("YYMM").substring(2));
        System.out.println("ym的值(今天)：" + ym);
        int tym = Integer.parseInt(tranYm.substring(2));
        System.out.println("tym的值(查询年月)：" + tym);
        int lateM = 0;
        if (tym > ym) {
            lateM = ym + 13 - tym;
        } else {
            lateM = ym + 1 - tym;
        }
        return lateM;
    }

    protected static String getTransTime(String timeFormat) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
        return sdf.format(date);
    }
}
